package cn.promonkey.core.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author gongym
 */
@Configuration
@MapperScan(value = {"cn.promonkey.api.**.mapper*"})
public class MybatisPlusConfig {

    /**
     *     //配置分页插件(过时了！！！)
     *     // 可以用，但是可以total的值会一直显示为0
     *     @Bean
     *     public PaginationInnerInterceptor paginationInnerInterceptor() {
     *         PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
     *         // 设置最大单页限制数量，默认 500 条，-1 不受限制
     *         paginationInterceptor.setMaxLimit(-1L);
     *         paginationInterceptor.setDbType(DbType.MYSQL);
     *         // 开启 count 的 join 优化,只针对部分 left join
     *         paginationInterceptor.setOptimizeJoin(true);
     *         return paginationInterceptor;
     *     }
     */
 
    // 新版本的方法就是  MybatisPlusInterceptor
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
    	
    	PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
        // 设置最大单页限制数量，默认 500 条，-1 不受限制
        paginationInterceptor.setMaxLimit(-1L);
        paginationInterceptor.setDbType(DbType.MYSQL);
        // 开启 count 的 join 优化,只针对部分 left join
        paginationInterceptor.setOptimizeJoin(true);
    	
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(paginationInterceptor);
        return interceptor;
    }


}
